<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Data extends CI_Controller {
	
	function __construct(){
		parent::__construct();
	}
	
	/**
	 * 用户注册
	 */
	function reg(){
		$ret['code'] = 0;
		$data = array(
			'username'      => trim($this->input->get_post('username')),
			'email'         => trim($this->input->get_post('email')),
			'password'		=> md5(md5($this->input->get_post('password'))),
			'email_status'  => '0',
			'type_id'       => '2',
			'add_time'      => time(),
			'addip'         => $this->js->get_ip(),
		);
		if ($data['username']==""){
			$ret['msg'] = '用户名不能为空';
			$ret['code'] = 1;
		}elseif(!isset($data['username'][2])){
			$ret['msg'] = '用户名太短';
			$ret['code'] = 2;
		}elseif(!$this->myformcheck->isName($data['username'])){
			$ret['msg'] = '非法的用户名';
			$ret['code'] = 3;
		}elseif($data['email']==""){
			$ret['msg'] = '邮箱不能为空';
			$ret['code'] = 4;
		}elseif(!$this->myformcheck->isEmail($data['email'])){
			$ret['msg'] = '无效的邮箱';
			$ret['code'] = 5;
		}elseif ($this->input->get_post('password')==""){
			$ret['msg'] = '密码不能为空';
			$ret['code'] = 6;
		}else{
			$this->load->model('User_model', 'user');
			if($this->user->get_one(array('username'=>$data['username']), 'user_id')){
				$ret['msg'] = '用户名已存在';
				$ret['code'] = 8;
			}elseif($this->user->get_one(array('email'=>$data['email']), 'user_id')){
				$ret['msg'] = '邮箱已存在';
				$ret['code'] = 9;
			}else{
				/** UC同步注册 */
				/*include './config.inc.php';
				include './uc_client/client.php';
				$uid = uc_user_register(iconv('UTF-8', 'GBK', $data['username']), $this->input->get_post('password'), $data['email']);
				if($uid <= 0) {
					if($uid == -1) {
						$ret['msg'] = '非法的用户名';
						$ret['code'] = 3;
					} elseif($uid == -2) {
						$ret['msg'] = '非法的用户名';
						$ret['code'] = 3;
					} elseif($uid == -3) {
						$ret['msg'] = '用户名已存在';
						$ret['code'] = 8;
					} elseif($uid == -4) {
						$ret['msg'] = '无效的邮箱';
						$ret['code'] = 5;
					} elseif($uid == -5) {
						$ret['msg'] = '该邮箱不允许注册';
						$ret['code'] = 10;
					} elseif($uid == -6) {
						$ret['msg'] = '邮箱已存在';
						$ret['code'] = 9;
					} else {
						$ret['msg'] = '论坛注册失败，请与客服联系';
						$ret['code'] = 11;
					}
				}else{*/
					$user_id = $this->user->add($data);
					if($user_id){
						$msg = array(
							'user_id'=> $user_id,
							'username' => $data['username'],
							'webname' => CON_PLATFORMNAME,
							'email' => $data['email']
						);
						//发送注册邮件
						$this->load->library('func');
						$this->load->library('/phpmailer/PHPMailer');
						$msgBody = $this->func->regEmailMsg($msg);
						$this->phpmailer->IsSMTP();
						$this->phpmailer->AddAddress($data['email'], $data['username']);//收件人
						$this->phpmailer->Subject 	= CON_PLATFORMNAME."注册认证";
						$this->phpmailer->Body 		= $msgBody;
						$res = $this->phpmailer->Send();
						
						$ret['msg'] = '注册成功，请尽快前往邮箱激活';
						$ret['code'] = 0;
					}else{
						$ret['msg'] = '注册失败，请联系客服';
						$ret['code'] = 11;
					}
				//}
			}
		}
		echo json_encode($ret);
	}
	
	/**
	 * 登录
	 */
	function login(){
		$username = $this->input->get_post('username');
		$password = $this->input->get_post('password');
		
		$ret['code'] = 0;
		if($username==''){
			$ret['msg'] = '请输入用户名或邮箱';
			$ret['code'] = 1;
		}elseif ($password==''){
			$ret['msg'] = '请输入密码';
			$ret['code'] = 2;
		}else{
			$this->load->model('User_model', 'user');
			$tmpRow = $this->user->check_login_errnum( $this->input->get_post('username'));
			if($tmpRow && $tmpRow['error_num']>=5){
				$ret['msg'] = '密码输入错误过多，该账户已被锁定，请联系客服解锁或者明日再试';
				$ret['code'] = 3;
			}else{
				$user = $this->user->check_login($username,$password);
				if(isset($user['user_id'])){
					if($user['fstatus']==3){
						$ret['msg'] = '该账户已注销';
						$ret['code'] = 4;
					}elseif ($user['fstatus']==4){
						$ret['msg'] = '该账户已冻结';
						$ret['code'] = 5;
					}else{
						$ip = $this->input->ip_address();
						$now = time();
						$user['login_time'] = $now;
						//$this->session->set_userdata('ych_user',$user);
						$user = $this->user->get_by_uid($user['user_id']);
						$setArr = array(
							'logintime' => $user['logintime']+1,
							'uptime' => $user['lasttime'],
							'upip' => $user['lastip'],
							'lasttime' => $now,
							'error_num' => 0,
							'lastip' => $ip,
						);
						$this->user->update($setArr,array('user_id'=>$user['user_id']));
						
						//新增 添加登录日志
						/*$addLog = array(
							'login_name' => $data['username'],
							'login_state' => 1,
							'login_time' => $now,
							'login_ip' => $ip
						);
						$this->user->add_user_login_log($addLog);*/
						
						$retUser = array(
							'user_id' => $user['user_id'],
							'username' => $user['username'],
							'email' => $user['email'],
							'realname' => $user['realname'],
							'phone' => $user['phone'],
							//'qq' => $user['qq'],
						);
						
						$token_time = time();
						$token_val = md5($user['user_id'].$user['username'].time());
						$token_key = 'token_'.$user['user_id'];
						$this->mycache->set($token_key,$token_val,3600*24);
						
						//VIP
						$this->load->model('User_vip_model');
						$vipInfo = $this->User_vip_model->get_by_uid($user['user_id']);
						$vip_end = '';
						if (isset($vipInfo['vip_status']) && $vipInfo['vip_status']==1){
							$vip_end = date('Y-m-d',$vipInfo['vip_verify_time']+3600*24*365);
						}
						$retUser['vipTime'] = $vip_end;
						//积分
						$this->load->model('Credit_model');
						$creditInfo = $this->Credit_model->get_row($user['user_id']);
						$retUser['creditValue'] = $creditInfo['credit_value'];//用户积分
						
						
						$ret['msg'] = '登录成功';
						$ret['token'] = $token_val;
						$ret['user'] = $retUser;
						$ret['code'] = 0;
					}
				}else{
					$ret['msg'] = '账户或密码错误，请重试';
					$ret['code'] = 6;
				}
			}
		}
		echo json_encode($ret);
	}
	
	/**
	 * 修改密码
	 */
	function setpwd(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if($user_id && $token == $token_val){
			$oldPwd = $this->input->get_post('old_pwd');
			$newPwd = $this->input->get_post('new_pwd');
			
			if(!$oldPwd){
				$ret['msg'] = '请输入旧密码';
				$ret['code'] = 2;
				echo json_encode($ret);exit;
			}elseif (!$newPwd){
				$ret['msg'] = '新密码不能为空';
				$ret['code'] = 3;
				echo json_encode($ret);exit;
			}elseif (!isset($newPwd[5])){
				$ret['msg'] = '新密码长度不够';
				$ret['code'] = 4;
				echo json_encode($ret);exit;
			}else{
				//$user_id = $user['user_id'];
				$this->load->model('User_model', 'user');
				$user = $this->user->get_by_uid($user_id);
				
				if(md5(md5($oldPwd)) == $user['password']){
					$res = $this->user->update(array('password'=>md5(md5($newPwd))),array('user_id'=>$user_id));
					//uc修改密码
					/*include './config.inc.php';
					include './uc_client/client.php';
					$int = uc_user_edit($user['username'], $oldPwd, $newPwd, '');
					if($int){
						require_once './include/db_mysql.class.php';
						$db = new dbstuff;
						$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset ? $dbcharset : 'utf-8');
						$tmpRow = $db->fetch_first("SELECT * FROM ".$tablepre."members WHERE username='{$user['username']}'");
						$newUcPwd = md5(md5($newPwd).$tmpRow['salt']);
						$db->query("UPDATE ".$tablepre."members SET password='$newUcPwd' WHERE username='{$user['username']}'");
					}*/
					if ($res){
						$this->mycache->delete($token_key);
						$ret['msg'] = '操作成功';
						$ret['code'] = 0;
						echo json_encode($ret);exit;
					}else{
						$ret['msg'] = '操作失败';
						$ret['code'] = 7;
						echo json_encode($ret);exit;
					}
					
				}else{
					$ret['msg'] = '旧密码不正确';
					$ret['code'] = 6;
					echo json_encode($ret);exit;
				}
			}
			
		}else{
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
	}
	
	/**
	 * 找回密码
	 */
	function getpwd(){
		$username = $this->input->get_post('username');
		$email = $this->input->get_post('email');
		if (!$username || !$email){
			$ret['msg'] = '请先填写用户名和邮箱';
			$ret['code'] = 2;
			echo json_encode($ret);exit;
		}
		$this->load->model('User_model', 'user');
		$where = array(
			'username' => $username,
			'email' => $email
		);
		$userinfo = $this->user->get_one($where,'user_id');
		if(!$userinfo){
			$ret['msg'] = '邮箱和用户名不匹配';
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}
		$msg = array(
			'user_id'=> $userinfo['user_id'],
			'username' => $username,
			'webname' => CON_PLATFORMNAME,
			'email' => $email
		);
		$this->load->library('func');
		$this->load->library('/phpmailer/PHPMailer');
		$msgBody = $this->func->findPwdMail($msg);
		$this->phpmailer->IsSMTP();
		$this->phpmailer->AddAddress($email, $username);//收件人
		$this->phpmailer->Subject 	= CON_PLATFORMNAME."登陆密码找回";
		$this->phpmailer->Body 		= $msgBody;
		$res = $this->phpmailer->Send();
		if($res){
			$ret['code'] = 0;
			$ret['msg'] = '邮件发送成功，请从邮件内容里的链接地址重置密码，该链接有效时间1小时，请及时操作！';
		}else{
			$ret['code'] = 1;
			$ret['msg'] = '邮箱发送失败，请稍后再试或者联系客服！';
		}
		echo json_encode($ret); 
		exit;
	}
	
	
	/**
	 * 登出
	 */
	function logout(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->delete($token_key);
		
		$ret['msg'] = '您已退出';
		$ret['code'] = 0;
		echo json_encode($ret);
	}
	
	
	/**
	 * 用户账户信息
	 */
	function useraccount(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		
		if($user_id && $token_val && $token == $token_val){
			$this->load->model('Account_model');
			$this->load->model('Borrow_model');
			$this->load->model('Yjb_model');
			
			$accountInfo = $this->Account_model->get_account($user_id);
			
			if(!$accountInfo){
				$initAccount = array(
					'user_id'      => $user_id,
					'total'        => 100,
					'use_money'    => '0',
					'no_use_money' => '0',
					'collection'   => '0',
					'reg_money'    => 100
				);
				
				$account_id = $this->Account_model->init_account($initAccount);
				if($account_id) $initAccount['id'] = $account_id;
				$accountInfo = $initAccount;
			}
			
			//代收
			$collection_list = $this->Borrow_model->collection_total($user_id, 0);
			$yjb_data = $this->Yjb_model->get_total($user_id);
			//代收本金
			$collection_capital = $collection_list['collection_capital']+$yjb_data['daishou']['account'];
			//代收利息
			$collection_interest = $collection_list['collection_interest']+$yjb_data['daishou']['interest'];
			//最近回款时间
			$first_collection_time = $this->Borrow_model->first_collection_time($user_id);
			$yjbFirstRepayTime = $this->Yjb_model->first_repay_time($user_id);
			if (!$first_collection_time){
				$first_collection_time = $yjbFirstRepayTime;
			}else{
				if ($yjbFirstRepayTime){
					$first_collection_time = min($first_collection_time,$yjbFirstRepayTime);
				}
			}
			$this->load->model('Accountlog_model');
			$cash_fee = $this->Accountlog_model->cash_fee($user_id);
			$cash_fee = min($cash_fee,$accountInfo['use_money']);
			
			$ret['code'] = 0;
			$ret['account'] = array(
				'user_id'=>$user_id,
				'total'=>$accountInfo['total'],
				'use_money'=>$accountInfo['use_money'],
				'no_use_money'=>$accountInfo['no_use_money'],
				'collection'=>$accountInfo['collection'],
				'collection_capital' => $collection_capital,
				'collection_interest' => $collection_interest,
				'first_collection_time' => $first_collection_time?date('Y-m-d',$first_collection_time):'',
				'cash_free'=>$cash_fee
			);
			
			echo json_encode($ret);
		}else{
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);
		}
	}
	
	/**
	 * 首页banner图
	 */
	function banner(){
		//获取滚动图片
		$this->load->model('scrollpic_model');
		$scrollpic_list = $this->scrollpic_model->get_scrollpic_list_index();
		$images = array();
		foreach ($scrollpic_list as $val){
			$images[] = SCROLLPIC_IMG.$val['pic'];
		}
		$ret['code']=0;
		$ret['images'] = $images;
		echo json_encode($ret);
	}
	
	/**
	 * 首页统计数据
	 */
	function intotal(){
		$this->load->model('Account_model');
		$this->load->model('Yjb_model');
		$tongji = $this->Account_model->index_tongji();
		$yjbTotal = $this->Yjb_model->yjb_total();
		$tongji['interest'] = $tongji['interest']+$yjbTotal['interest'];
		$tongji['account'] = $tongji['account']+$yjbTotal['account'];
		$ret = array(
			'code'=>0,
			'tongji'=>$tongji
		);
		echo json_encode($ret);
	}
	
	/**
	 * 首页易居宝
	 */
	function inyjb(){
		$this->load->model('Mydb_model','mydb');
		$sql = "select * from ych_yjb_borrow where fstatus in(2,3,4) order by id desc limit 1";
		$yjb = $this->mydb->query_sql($sql,'row');
		$aprList = json_decode($yjb['apr_list'],true);
		/*$tmp = array();
		$i=1;
		foreach ($aprList as $val){
			$k = "time_".$i;
			$tmp[$k] = $val;
			$i=$i+1;
		}*/
		$ret = array(
			'code'=>0,
			'info'=>array(
				'id'=>$yjb['id'],
				'title'=>$yjb['title'],
				'account'=>$yjb['account'],
				'account_yes'=>$yjb['account_yes'],
				'apr_list'=>$aprList
			)
		);
		echo json_encode($ret);
	}
	
	/**
	 * 易居宝详情
	 */
	function yjbinfo(){
		$id = intval($this->input->get_post('id'));
		$this->load->model('Yjb_model');
		$yjb = $this->Yjb_model->get_by_id($id);
		$aprList = json_decode($yjb['apr_list'],true);
		/*$tmp = array();
		$i=1;
		foreach ($aprList as $val){
			$k = "time_".i;
			$tmp[$k] = $val;
			$i=$i+1;
		}*/
		$ret = array(
			'code'=>0,
			'info'=>array(
				'id'=>$yjb['id'],
				'title'=>$yjb['title'],
				'account'=>$yjb['account'],
				'account_yes'=>$yjb['account_yes'],
				'lowest_account'=>$yjb['lowest_account'],
				'one_account'=>$yjb['one_account'],
				'valid_time'=>$yjb['valid_time'],
				'content'=>$yjb['content'],
				'apr_list'=>$aprList
			)
		);
		echo json_encode($ret);
	}
	
	/**
	 * 易居宝投标记录
	 */
	function yjbtenders(){
		$id = intval($this->input->get_post('id'));
		$page = intval($this->input->get_post('page'));
		$this->load->model('Yjb_model');
		if ($id>0){
			$page_size = 20;
			$page = max($page,1);
			$limit = ($page-1)*$page_size;
			$where = array(
				'yjb_id'=>$id,
				'per_page'=>$limit,
				'page_size'=>$page_size
			);
			$result = $this->Yjb_model->tender_list($where);
			$tender_list = $result['list'];
			$list = array();
			$status = array(
				'1'=>'已通过',
				'3'=>'已还完'
			);
			foreach ($tender_list as $val){
				$list[] = array(
					'id'=>$val['id'],
					'username'=>$val['username'],
					'account'=>$val['account'],
					'time_limit_day'=>$val['time_limit_day'],
					'add_time'=>date('Y-m-d H:i:s',$val['add_time']),
					'state'=>$status[$val['fstatus']],
				);
			}
			$ret = array(
				'code'=>0,
				'page'=>$page,
				'page_size'=>$page_size,
				'total'=>$result['count'],
				'list'=>$list
			);
			echo json_encode($ret);
		}else{
			$ret = array(
				'code'=>1,
				'msg'=>'数据错误'
			);
			echo json_encode($ret);
		}
		
	}
	
	/**
	 * 易居宝投标
	 */
	function yjbtender(){
		$ret = array(
			'code'=>0,
			'msg'=>''
		);
		
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		
		if($user_id && $token_val && $token == $token_val){
			$id 			= intval($this->input->get_post("id"));
			$account 		= intval($this->input->get_post("account"));
			$timeLimit 		= intval($this->input->get_post("time_limit"));
			$paypassword 	= $this->input->get_post("paypassword");
			
			$this->load->model('User_model');
			$this->load->model('Yjb_model');
			$this->load->model('Account_model');
			
			$yjb = $this->Yjb_model->get_by_id($id);
			if (!$yjb){
				$ret['code'] = 2;
				$ret['msg'] = '数据错误';
				echo json_encode($ret);
				exit;
			}
			
			$pay_result = $this->User_model->check_paypassword($user_id, $paypassword);
			if(!$pay_result){
				$ret['code'] = 3;
				$ret['msg'] = '支付密码不正确';
			}elseif(!$this->myformcheck->IsDouble($account)){
				$ret['code'] = 4;
				$ret['msg'] = '投标金额不正确';
			}elseif((time()-$yjb['verify_time']) > ($yjb['valid_time']*3600*24)){
				$ret['code'] = 4;
				$ret['msg'] = '此标已过期';
			}elseif($yjb['account'] <= $yjb['account_yes']){
				$ret['code'] = 5;
				$ret['msg'] = '此标已满';
			}elseif($yjb['lowest_account'] > $account){
				$ret['code'] = 6;
				$ret['msg'] = '最低投标金额为'.$yjb['lowest_account'];
			}elseif($account%$yjb['one_account'] > 0){
				$ret['code'] = 7;
				$ret['msg'] = '必须为'.$yjb['one_account'].'的倍数';
			}elseif(($yjb['most_account'] > 0) && ($account > $yjb['most_account'])){
				$ret['code'] = 8;
				$ret['msg'] = '投标金额超过最大投标金额';
			}elseif($yjb['user_id'] == $user_id){
				$ret['code'] = 9;
				$ret['msg'] = '不能投自己的标';
			}
			
			if ($ret['code']>0){
				echo json_encode($ret);
				exit;
			}
			
			$money = $account;
			if($yjb['account'] - $yjb['account_yes'] < $account){
				$account = $yjb['account'] - $yjb['account_yes'];
			}
			$user_account = $this->Account_model->get_account($user_id);
			if ($account<=0){
				$ret['code'] = 10;
				$ret['msg'] = '无效的金额';
				echo json_encode($ret);
				exit;
			}
			if($user_account['use_money'] < $account){
				$ret['code'] = 11;
				$ret['msg'] = '您的可用金额不足，请先充值';
				echo json_encode($ret);
				exit;
			}
			
			//体验金检验
			$expMoney = $user_account['exp_money_12']+$user_account['exp_money_24'];
			if ($user_account['use_money']-$account<$expMoney){
				$ret['code'] = 12;
				$ret['msg'] = '体验金只能用于投资相应标种';
				echo json_encode($ret);
				exit;
			}
			
			$aprList = json_decode($yjb['apr_list'],true);
			$apr = $award = 0;
			foreach ($aprList as $val){
				if ($timeLimit==$val['time_limit']){
					$apr = $val['apr'];
					$award = $val['award'];
				}
			}
			//暂时先不考虑奖励
			$data['user_id'] = $user_id;
			$data['fstatus'] = 1;
			$data['yjb_id'] = $id;
			$data['money'] = $money;
			$data['account'] = $account;
			$data['time_limit_day'] = $timeLimit;
			$data['apr'] = $apr;
			$data['add_time'] = time();
			$data['addip'] = $this->js->get_ip();
			$res = $this->Yjb_model->invest($data);
			
			if ($res){
				$ret['code'] = 0;
				$ret['msg'] = '投标成功';
			}else{
				$ret['code'] = 13;
				$ret['msg'] = '投标失败';
			}
			echo json_encode($ret);
			exit;
			
		}else{
			$ret = array(
				'code'=>1,
				'msg'=>'请先登录'
			);
			echo json_encode($ret);
			exit;
		}
	}
	
	/**
	 * 首页流转标列表
	 */
	function inborrow(){
		$this->load->model('Borrow_model');
		$adata['page_size']  = 5;
		$adata['page_start'] = 0;
		$adata['select'] 	= 1;
		$adata['list'] 		= 1;
		$adata['where']['order'] = 'index';
		$adata['where']['is_index'] = 1;
		$bdata = $this->Borrow_model->get_borrow_list($adata);
		foreach ($bdata as $k => $b){
			if ($b['account_yes'] >= $b['account']){
				$bdata[$k]['repayment_time']=$this->Borrow_model->lz_last_tender($b['id']);
			}
		}
		$bdata1 = $bdata2 = array();
		foreach ($bdata as $k => $b){
			if ($b['id']!=3054 && $b['is_kjb']!=1){
				if ($b['account_yes'] != $b['account']){
					$bdata1[]=$b;
				}else{
					if($b['repayment_time']>=strtotime('2013-12-08')){
						$bdata2[]=$b;
					}
				}
			}
		}
		$this->load->library('func');
		$bdata2 = $this->func->array_sort($bdata2,'repayment_time','desc');
		$bdata3 = array_merge($bdata1,$bdata2);
		
		$borrow_list = array();
		foreach ($bdata3 as $k=>$val){
			$borrow_list[$k] = array(
				'id'=>$val['id'],
				'type'=>$val['ftype'],
				'title'=>$val['title'],
				'account'=>$val['account'],
				'time_limit'=>$val['time_limit'],
				'apr'=>$val['apr'],
				'account_yes'=>$val['account_yes'],
			);
		}
		$ret = array(
			'code'=>0,
			'borrow_list'=>$borrow_list
		);
		echo json_encode($ret);
	}
	
	/**
	 * 流转标详情
	 */
	function borrowinfo(){
		$id = intval($this->input->get_post("id"));
		$this->load->model('Borrow_model');
		
		$data['select'] = 1;
		$borrow_obj = $this->Borrow_model->get_borrow_obj($id, $data);
		$borrowType	= $this->Borrow_model->arrays('borrow_type1');//标种
		
		$tmpBo = array();
		$tmpBo['id'] = $borrow_obj['id'];//借款ID
		$tmpBo['title'] = $borrow_obj['title']; //借款标题
		$tmpBo['type'] = $borrow_obj['ftype'];//借款类型ID[4为流转标]
		$tmpBo['is_dxb'] = $borrow_obj['is_dxb'];//借款类型ID[4为流转标]
		$tmpBo['type_name']    = isset($borrowType[$borrow_obj['ftype']]) ? $borrowType[$borrow_obj['ftype']] : '';//借款类型
		$tmpBo['account'] = $borrow_obj['account'];//借款金额
		$tmpBo['time_limit'] = $borrow_obj['time_limit'];//借款期限[多少月,如果是天标则使用下面字段]
		$tmpBo['apr'] = $borrow_obj['apr'];//借款年利率
		$tmpBo['funds'] = $borrow_obj['funds'];//投标奖励百分比
		$tmpBo['account_yes'] = $borrow_obj['account_yes'];//已借到金额 用于计算进度条
		$tmpBo['lowest_account'] = $borrow_obj['lowest_account'];//最低投标金额[流转标则是每份金额]
		$tmpBo['content'] = $borrow_obj['content'];//借款详情
		
		$ret = array(
			'code'=>0,
			'info'=>$tmpBo
		);
		echo json_encode($ret);
	}
	
	/**
	 * 流转标投标记录
	 */
	function lztenders(){
		$id = intval($this->input->get_post('id'));
		$page = intval($this->input->get_post('page'));
		if ($id>0){
			$this->load->model('User_model');
			$this->load->model('Borrow_model');
			$page_size = 20;
			$parms = array(
				'page_start'=>($page-1)*$page_size,
				'page_size' => $page_size,
				'where'=>array('borrow_id'=>$id)
			);
			//$borrow_tender_list 			= $this->Borrow_model->get_borrow_tender($parms);
			$result = $this->Borrow_model->get_borrow_tender_lists($parms);
			
			$borrow_tender_list = $result['tender_list'];
			$borrow_tender_list1 = array();
			foreach ($borrow_tender_list as $tender){
				$user_obj = $this->User_model->get_by_uid($tender['user_id']);
				
				$tmpT = array();
				$tmpT['username'] = $user_obj['username'];//投标人用户名
				$tmpT['money'] = $tender['money'];//投标金额
				$tmpT['account'] = $tender['account'];//有效金额
				$tmpT['add_time'] = date('Y-m-d H:i:s',$tender['add_time']);;//投标时间
				$tmpT['state'] = '已通过';
				$borrow_tender_list1[] = $tmpT;
			}
			$ret['list'] = $borrow_tender_list1;
			$ret['code'] = 0;
			$ret['page'] = $page;
			$ret['page_size'] = $page_size;
			$ret['total'] = $result['tender_count'];
			echo json_encode($ret);
		}else{
			$ret['code']=1;
			$ret['msg']='数据错误';
			echo json_encode($ret);
			exit;
		}
		
	}
	
	/**
	 * 流转标投标
	 */
	function lztender(){
		$ret['msg'] = '';
		$ret['code'] = 0;
		$id 				= $this->input->get_post("id");
		$account 			= intval($this->input->get_post("account"));
		$paypassword 		= $this->input->get_post("paypassword");
		$dxb_pwd 			= $this->input->get_post("dxb_pwd")?$this->input->get_post("dxb_pwd"):"";
		
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || !$token || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		
		$this->load->model('User_model');
		$user = $this->User_model->get_by_uid($user_id);
		$this->load->model('Borrow_model');
		$this->load->model('Account_model');
		
		$borrow_obj = $this->Borrow_model->get_borrow_obj($id, array('select'=>1));
		if ($borrow_obj['ftype']!=4){
			$ret['msg'] = '入口错误';
			$ret['code'] = 8;
			echo json_encode($ret);exit;
		}
		$pay_result = $this->User_model->check_paypassword($user['user_id'], $paypassword);
		if($pay_result == '' || $pay_result == 0){
			$ret['msg'] = "支付密码不正确";
			$ret['code'] = 2;
			echo json_encode($ret);exit;
		}
		if(!$this->myformcheck->IsDouble($account)){
			$ret['msg'] = "投标金额不正确";
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}
		/*if(!$this->myformcheck->isNumber($money)){
			$ret['msg'] = "份额不正确";
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}*/
		if (($account%100)!=0){
			$ret['msg'] = "必须是100的倍数";
			$ret['code'] = 9;
			echo json_encode($ret);exit;
		}
		if($borrow_obj['account'] == $borrow_obj['account_yes']){
			$ret['msg'] = "此标已满";
			$ret['code'] = 4;
			echo json_encode($ret);exit;
		}
		if($borrow_obj['user_id'] == $user['user_id']){
			$ret['msg'] = "不能投自己的标";
			$ret['code'] = 5;
			echo json_encode($ret);exit;
		}
		if($borrow_obj['is_dxb'] == 1 && $dxb_pwd != $borrow_obj['dxb_pwd']){
			$ret['msg'] = "定向密码不正确";
			$ret['code'] = 6;
			echo json_encode($ret);exit;
		}
		//$account = $money*$borrow_obj['lowest_account'];
		$data['id'] 		= $id;
		$data['money'] 		= $account;
		$data['ip'] 		= $this->js->get_ip();
		$data['user_id'] 	= $user['user_id'];
		$data['borrow_id'] 	= $id;
		
		
		if($borrow_obj['account'] - $borrow_obj['account_yes'] < $account){
			$account = $borrow_obj['account'] - $borrow_obj['account_yes'];
		}
		$user_account = $this->Account_model->get_account($user['user_id']);
		if($user_account['use_money'] < $account){
			$ret['msg'] = "您的余额不足，请先充值";
			$ret['code'] = 7;
			echo json_encode($ret);exit;
		}
		//体验金检验
		$timeLimt = $borrow_obj['time_limit'];
		if ($timeLimt<12){
			$expMoney = $user_account['exp_money_12']+$user_account['exp_money_24'];
			if ($user_account['use_money']-$account<$expMoney){
				$ret['msg'] = "体验金只能用于投资相应标种";
				$ret['code'] = 11;
				echo json_encode($ret);exit;
			}
		}elseif ($timeLimt>12){
			$expMoney = $user_account['exp_money_12'];
			if ($user_account['use_money']-$account<$expMoney){
				$ret['msg'] = "体验金只能用于投资相应标种";
				$ret['code'] = 11;
				echo json_encode($ret);exit;
			}
		}
		$account = max(0, $account);
		$account = min($account, $user_account['use_money']);
		$data['account'] 	= $account;
		
		$data['borrow_user_id'] = $borrow_obj['user_id'];
		
		//注册体验金自动投标
		if ($data['account']>=300 && $borrow_obj['time_limit']>=12 && $user_account['reg_money']==100){
			if ($borrow_obj['account'] - $borrow_obj['account_yes'] - $data['account']>=100){
				$data['money'] = $data['money'] + 100;
				$data['account'] = $data['account'] + 100;
				$this->Borrow_model->reg_money_use(array('user_id'=>$user['user_id']));
			}
		}
		
		$flag = $this->Borrow_model->borrow_lz_tender($data);
		if ($flag){
			$ret['msg'] = "投标成功";
			$ret['code'] = 0;
			echo json_encode($ret);exit;
		}else{
			$ret['msg'] = "操作失败";
			$ret['code'] = 10;
			echo json_encode($ret);exit;
		}
		
	}
	
	/**
	 * 首页债权转让列表
	 */
	function increditor(){
		$this->load->model('Creditor_model');
		$creditorList = $this->Creditor_model->index_list();
		$list = array();
		foreach ($creditorList as $val){
			$list[] = array(
				'id'=>$val['id'],
				'title'=>$val['title'],
				'repay_total'=>$val['wait_account'],
				'repay_account'=>$val['account'],
				'discount_apr'=>$val['discount_apr'],
				'discount_account'=>$val['discount_account'],
				'discount_yes' => $val['discount_yes']
			);
		}
		$ret = array(
			'code'=>0,
			'list'=>$list
		);
		echo json_encode($ret);
	}
	
	/**
	 * 债权转让详情
	 */
	function creditor(){
		$ret = array();
		$id = intval($this->input->get_post("id"));
		$this->load->model('Creditor_model');
		$obj = $this->Creditor_model->get_obj_by_id($id);
		if (!in_array($obj['fstatus'], array(2,3))){
			$ret['code']=1;
			$ret['msg'] = '数据错误';
			echo json_encode($ret);
			exit;
		}
		
		$info = array(
			'id'=>$obj['id'],
			'title'=>$obj['title'],
			'repay_total'=>$obj['wait_account'],
			'repay_account'=>$obj['account'],
			'discount_apr'=>$obj['discount_apr'],
			'discount_account'=>$obj['discount_account'],
			'discount_yes' => $obj['discount_yes'],
			'verify_time'=>date('Y-m-d H:i:s',$obj['verify_time']),
			'valid_time'=>$obj['valid_time'],
			'content'=>$obj['content'],
		);
		$ret = array(
			'code'=>0,
			'info'=>$info
		);
		
		echo json_encode($ret);
		
	}
	
	/**
	 * 债权转让购买记录
	 */
	function cretransfers(){
		$this->load->model('Creditor_model');
		$id = intval($this->input->get_post("id"));
		$buyers = $this->Creditor_model->get_buyers($id);
		$list = array();
		$stateArr = array(1=>'待审核',2=>'已通过',3=>'已还完',4=>'已取消');
		foreach ($buyers as $v){
			$list[] = array(
				'username' => $v['username'],
				'account'=>$v['discount_buy'],
				'add_time'=>date('Y-m-d H:i:s',$v['add_time']),
				'state'=>$stateArr[$v['fstatus']]
			);
		}
		$ret = array(
			'code'=>0,
			'list'=>$list
		);
		echo json_encode($ret);
	}
	
	
	/**
	 * 债权转让
	 */
	function cretransfer(){
		$ret['msg'] = '';
		$ret['code'] = 0;
		
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || !$token || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		
		$this->load->model('User_model');
		$this->load->model('Account_model');
		$this->load->model('Creditor_model');
		
		$id = intval($this->input->get_post('id'));
		$money = $this->input->get_post('money');
		$paypassword = $this->input->get_post("paypassword");
		
		$obj = $this->Creditor_model->get_obj_by_id($id);
		if (!$obj){
			$ret['msg'] = '数据错误';
			$ret['code'] = 2;
			echo json_encode($ret);exit;
		}
		
		if(!$this->myformcheck->IsDouble($money)){
			$ret['msg'] = '金额不合法';
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}
		$money = round($money,2);
		
		$user = $this->User_model->get_by_uid($user_id);
		if (!$user || !isset($user['user_id'])){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$pay_result = $this->User_model->check_paypassword($user['user_id'], $paypassword);
		if(!$pay_result){
			$ret['msg'] = '支付密码不正确';
			$ret['code'] = 4;
			echo json_encode($ret);exit;
		}
		
		if((time()-$obj['verify_time']) > ($obj['valid_time']*3600*24)){
			$ret['msg'] = '此标已过期';
			$ret['code'] = 5;
			echo json_encode($ret);exit;
		}
		
		if ($obj['user_id']==$user['user_id']){
			$ret['msg'] = '不能购买自己的债权';
			$ret['code'] = 6;
			echo json_encode($ret);exit;
		}
		
		if ($obj['discount_yes']>=$obj['discount_account']){
			$ret['msg'] = '该债权已售完';
			$ret['code'] = 7;
			echo json_encode($ret);exit;
		}
		
		if($money < 100){
			$ret['msg'] = '最低购入金额100';
			$ret['code'] = 8;
			echo json_encode($ret);exit;
		}
		
		if($obj['discount_account'] - $obj['discount_yes'] < $money){
			$money = $obj['discount_account'] - $obj['discount_yes'];
		}
		
		$user_account = $this->Account_model->get_account($user['user_id']);
		if ($money<=0){
			$ret['msg'] = '金额不合法';
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}
		if($user_account['use_money'] < $money){
			$ret['msg'] = '您的可用金额不足，请先充值';
			$ret['code'] = 9;
			echo json_encode($ret);exit;
		}
		
		//体验金检验
		$expMoney = $user_account['exp_money_12']+$user_account['exp_money_24'];
		if ($user_account['use_money']-$money<$expMoney){
			$ret['msg'] = '体验金只能用于投资相应标种';
			$ret['code'] = 9;
			echo json_encode($ret);exit;
		}
		
		//$repay_account = 0;
		//取两位小数 不四舍五入
		//$repay_account = intval($obj['wait_account'] * ($money/$obj['discount_account']) *100)/100;
		//移到复审计算待收
		
		$data = array(
			'obj_id' => $id,
			'tender_id' => $obj['tender_id'],
			'fstatus' => 1,
			'user_id' => $user['user_id'],
			'discount_account' => $obj['discount_account'],
			'discount_buy' => $money,
			'repay_account' => 0,//待收金额
			'repay_yesaccount' => 0,//已收金额
			'add_time' => time(),
		);
		
		$ret = $this->Creditor_model->creditor_transfer($data);
		
		if ($ret){
			$ret['msg'] = '购买成功';
			$ret['code'] = 0;
			echo json_encode($ret);exit;
		}else{
			$ret['msg'] = '购买失败';
			$ret['code'] = 10;
			echo json_encode($ret);exit;
		}
	}
	
	/**
	 * 申请提现
	 */
	function cash(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		
		$this->load->model('User_model', 'user');
		$this->load->model('Account_bank_model', 'bank');
		$this->load->model('Account_model', 'account');
		$this->load->model('Accountlog_model', 'accountlog');
		$user = $this->user->get_by_uid($user_id);
		$bank = $this->bank->get_by_uid($user_id);
		$user_account = $this->account->get_account($user_id);
		$cash_fee = $this->accountlog->cash_fee($user_id);
		$cash_fee = min($cash_fee,$user_account['use_money']);
		
		if($user['real_status'] != 1){
			$ret['msg'] = '尚未实名认证';
			$ret['code'] = 2;
			echo json_encode($ret);exit;
		}elseif($user['phone_status'] != 1){
			$ret['msg'] = '尚未手机认证';
			$ret['code'] = 3;
			echo json_encode($ret);exit;
		}elseif($user['paypassword'] == ''){
			$ret['msg'] = '尚未设置交易密码';
			$ret['code'] = 4;
			echo json_encode($ret);exit;
		}elseif (!isset($bank['user_id'])){
			$ret['msg'] = '尚未填写银行账户';
			$ret['code'] = 5;
			echo json_encode($ret);exit;
		}
		$paypwd = $this->input->get_post('paypwd');//交易密码
		$money  = $this->input->get_post('money');//申请提现金额
		if(!is_numeric($money)){
			$ret['msg'] = '无效的金额';
			$ret['code'] = 6;
			echo json_encode($ret);exit;
		}
		$money = round($money,2);
		if($money < 100 || $money > 1000000){
			$ret['msg'] = '单笔提现金额超出范围(100-1000000)';
			$ret['code'] = 7;
			echo json_encode($ret);exit;
		}elseif(md5(md5($paypwd)) != $user['paypassword']){
			$ret['msg'] = '交易密码不正确';
			$ret['code'] = 8;
			echo json_encode($ret);exit;
		}elseif ($user_account['use_money'] < $money){
			$ret['msg'] = '可用余额不足';
			$ret['code'] = 9;
			echo json_encode($ret);exit;
		}else{
			$expMoney = $user_account['exp_money_12']+$user_account['exp_money_24'];
			if ($user_account['use_money']-$money<$expMoney){
				$ret['msg'] = '体验金不能用于提现';
				$ret['code'] = 10;
				echo json_encode($ret);exit;
			}
			//用户充值后七天内不可提现
			$dont_moeny = $this->accountlog->donnot_mention_weekend($user_id);
			
			$use_money = $user_account['use_money'] - $money;
			$use_money = round($use_money,2);
			$dont_moeny = round($dont_moeny,2)+$expMoney;
			
			if($use_money < $dont_moeny){
				$ret['msg'] = '充值7天内有'.$dont_moeny.'不可提现';
				$ret['code'] = 11;
				echo json_encode($ret);exit;
			}
			$this->load->model('Borrow_model');
			$daihuanMoney =  $this->Borrow_model->no_repayment_borrow_3($user['user_id']);//未还的净值标总额
			$nowJzMoney = $this->Borrow_model->now_borrow_3($user['user_id']);//正在招标的净值标总额
			$jingMaxFx = $this->Borrow_model->jing_max_faxi($user['user_id']);//获取用户净值标最高罚息
			//代收总额
			$daishouMoney = $user_account['collection'];
			if($daishouMoney-$daihuanMoney-$nowJzMoney-$jingMaxFx < 0){//（待收总额—待还总额—最高罚息）小于零时：
				//可提现金额=可用余额+（待收总额—净值标待还总额—最高罚息）
				if($user_account['use_money']+($daishouMoney-$daihuanMoney-$nowJzMoney-$jingMaxFx) < $money){
					//$this->js->alert('您可提现金额不能超过'.($account_result['use_money']+($daishouMoney-$daihuanMoney-$nowJzMoney-$jingMaxFx)));
					$ret['msg'] = '您可提现金额不能超过'.($user_account['use_money']+($daishouMoney-$daihuanMoney-$nowJzMoney-$jingMaxFx));
					$ret['code'] = 12;
					echo json_encode($ret);exit;
				}
			}
			$time = time();
			$ip = $this->js->get_ip();
			$fee = 0;
			if($user['is_loan']==0 && $cash_fee < $money){
				$fee = round(($money - $cash_fee) * 0.005,2);
			}
			$this->db->trans_begin();//事务开始
			//添加提现表记录
			$setArr = array(
				'user_id' => $user_id,
				'fstatus' => '0',
				'account' => $bank['account'],
				'bank' => $bank['bank'],
				'branch' => $bank['branch'],
				'province' => $bank['province'],
				'city' => $bank['city'],
				'total' => $money,
				'credited' => $money - $fee,
				'fee' =>$fee,
				'add_time' => $time,
				'addip' => $ip
			);
			$this->load->model('Accountcash_model', 'cash');
			$ret = $this->cash->add($setArr);
			//添加提现冻结资金日志
			if($ret > 0){
				$log = array(
					'user_id' => $user_id,
					'ftype' => CASH_FROST,
					'money' => $money,
					'total' => $user_account['total'],
					'use_money' => $user_account['use_money']-$money,
					'no_use_money' => $user_account['no_use_money']+$money,
					'collection' => $user_account['collection'],
					'to_user' => 0,
					'add_time' => $time,
					'addip' => $ip,
					'remark' => "提现冻结"
				);
				$ret = $this->account->addlog($log);
			}
			if($ret){
				$this->db->trans_commit();
				$ret['msg'] = '提现申请已提交，请等待审核';
				$ret['code'] = 0;
				echo json_encode($ret);exit;
			}else{
				$this->db->trans_rollback();
				$ret['msg'] = '操作失败，请重试';
				$ret['code'] = 13;
				echo json_encode($ret);exit;
			}
		}
		
		
		
	}
	
	/**
	 * 提现记录
	 */
	function cashed(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data = array();
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		//充值统计
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){
			$tmp = array();
			$tmp['total'] 	= number_format($cash['total'],2);//提现金额
			$tmp['fee'] 	= number_format($cash['fee'],2);//提现手续费
			$tmp['add_time'] = date('m-d H:i', $cash['add_time']);//提现时间
			$tmp['fstatus_text'] = $cash_status[$cash['fstatus']];//状态
			$cash_lsit1[] = $tmp;
		}
		$ret = array(
			'code'=>0,
			'list'=>$cash_lsit1,
			'page'=>$page,
			'page_size'=>$parms['page_size'],
			'total'=>$resData['accountcash_count']
		);
		
		echo json_encode($ret);
	}
	
	/**
	 * 充值记录
	 */
	function rechargelog(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data = array();
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] 	= $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$recharge_type 			= $this->recharge->arrays("account_recharge_type");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){
			$tmp = array();
			$tmp['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';//充值方式
			$tmp['money'] 			= number_format($recharge['money'],2);//充值金额
			$tmp['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];//状态
			$tmp['add_time'] 		= date('m-d H:i', $recharge['add_time']);//充值时间
			$recharge_list[] = $tmp;
		}
		$ret = array(
			'code'=>0,
			'list'=>$recharge_list,
			'page'=>$page,
			'page_size'=>$parms['page_size'],
			'total'=>$resData['accountrecharge_count']
		);
		echo json_encode($ret);
	}
	
	/**
	 * 资金明细记录
	 */
	function accountlog(){
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){
			$tmp = array();
			$tmp['ftype'] 		= $log_type[$account_log['ftype']];//资金操作类型
			$tmp['money'] 		= number_format($account_log['money'],2);//操作资金
			$tmp['add_time'] 	= date('m-d H:i', $account_log['add_time']);//操作时间
			$account_log_list1[] = $tmp;
		}
		$ret = array(
			'code'=>0,
			'list'=>$account_log_list1,
			'page'=>$page,
			'page_size'=>$parms['page_size'],
			'total'=>$resData['accountlog_count']
		);
		
		echo json_encode($ret);
	}
	
	/**
	 * 公告列表
	 */
	function notices(){
		//获取公告
		$page = intval($this->input->get_post('page'));
		$page = $page ? $page : 1;
		$cdata['where']['nid'] = 22;
		$cdata['page_size']  = 8;
		$cdata['page_start'] = ($page-1)*$cdata['page_size'];
		$cdata['select'] 	= 1;
		$this->load->model('article_model');
		$resData = $this->article_model->get_article_list($cdata);
		//$data['list'] = $list;
		$list = array();
		foreach ($resData['article_list'] as $key => $val){
			$tmpNotice = array();
			$tmpNotice['id'] = $val['id'];
			$tmpNotice['title'] = $val['title'];
			$tmpNotice['ptime'] = date('Y-m-d', $val['ptime']);
			$list[] = $tmpNotice;
		}
		$ret = array(
			'code'=>0,
			'list'=>$list,
			'page'=>$page,
			'page_size'=>$cdata['page_size'],
			'total'=>$resData['article_count']
		);
		echo json_encode($ret);
	}
	
	/**
	 * 公告详情
	 */
	function notice(){
		$id = intval($this->input->get_post('id'));
		$this->load->model('article_model');
		$article = $this->article_model->get_article_obj($id);
		if ($article){
			$info = array(
				'id'=>$id,
				'title'=>$article['title'],
				'ptime'=>date('Y-m-d', $article['ptime']),
				'content'=>$article['content']
			);
			echo json_encode($info);
		}
		
	}
	
	/**
	 * 待收明细
	 */
	function coll(){
		$page = intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data['where']['user_id'] 	= $user_id;
		$data['where']['fstatus'] 	= 0;
		$data['select'] 	= 1;
		$data['order'] 		= 1;
		$data['page_size']  = 8;
		$data['page_start'] = ($page-1)*$data['page_size'];
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$tmpColl = array();
			$tmpColl['title'] 	= utf8substr($coll['title'], 0, 8);//标题
			$tmpColl['repay_time'] = date('m-d H:i', $coll['repay_time']);//应收时间
			$tmpColl['capital'] 	= number_format($coll['capital'], 2);//应收本金
			$tmpColl['interest'] 	= number_format($coll['interest'], 2);//应收利息
			$collection_list[] = $tmpColl;
		}
		$ret = array(
			'code'=>0,
			'list'=>$collection_list,
			'page'=>$page,
			'page_size'=>$data['page_size'],
			'total'=>$res_data['collection_count']
		);
		echo json_encode($ret);
	}
	
	/**
	 * 已收明细
	 */
	function ycoll(){
		$page = intval($this->input->get_post('page'));
		$page = $page ? $page : 1;
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data['where']['user_id'] 	= $user_id;
		$data['where']['fstatus'] 	= 1;
		$data['select'] 	= 1;
		$data['order'] 		= 4;
		$data['page_size']  = 8;
		$data['page_start'] = ($page-1)*$data['page_size'];
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$tmpColl = array();
			$tmpColl['title'] 	= utf8substr($coll['title'], 0, 8);//标题
			$tmpColl['repay_yestime'] = date('m-d H:i', $coll['repay_yestime']);//收款时间
			$tmpColl['capital'] 	= number_format($coll['capital'], 2);//本金
			$tmpColl['interest'] 	= number_format($coll['interest'], 2);//利息
			$collection_list[] = $tmpColl;
		}
		$ret = array(
			'code'=>0,
			'list'=>$collection_list,
			'page'=>$page,
			'page_size'=>$data['page_size'],
			'total'=>$res_data['collection_count']
		);
		echo json_encode($collection_list);
	}
	
	
}
